﻿@{
    ViewData["Title"] = "修改现有库存";
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.17/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    <!-- 给容器追加 class="layui-form-pane"，即可显示为方框风格 -->
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">产品物料编码</label>
            <div class="layui-input-block">
                <input type="text" name="ItemCode" id="ItemCode" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
            <input type="checkbox" checked lay-skin="switch" lay-filter="switchTest" title="自动生成">
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">产品物料名称</label>
            <div class="layui-input-block">
                <input type="text" name="ItemName" id="ItemName" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">库存数量</label>
            <div class="layui-input-block">
                <input type="text" name="Quantity" id="Quantity" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">单位</label>
            <div class="layui-input-block">
                <input type="text" name="UnitOfMeasure" id="UnitOfMeasure" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">

            <label class="layui-form-label">入库批次编号</label>
            <div class="layui-input-block">
                <input type="text" name="BatchCode" id="BatchCode" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">仓库名称</label>
            <div class="layui-input-block">
                <input type="text" name="WarehouseName" id="WarehouseName" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">库区名称</label>
            <div class="layui-input-block">
                <input type="text" name="LocationName" id="LocationName" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">库位名称</label>
            <div class="layui-input-block">
                <input type="text" name="AreaName" id="AreaName" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-form-item">
                <button class="layui-btn" lay-submit lay-filter="demo2">修改</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>

    </form>

    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
    <script src="//unpkg.com/layui@2.9.17/dist/layui.js"></script>
    <script>
        layui.use(['form'], function () {
            var layer = layui.layer;
            var form = layui.form;
            //反填
            function generateVendorCode() {
                $("#ItemCode").val(parent.ItemCode);
                $("#ItemName").val(parent.ItemName);
                $("#Quantity").val(parent.Quantity);
                $("#UnitOfMeasure").val(parent.UnitOfMeasure);
                $("#BatchCode").val(parent.BatchCode);
                $("#WarehouseName").val(parent.WarehouseName);
                $("#LocationName").val(parent.LocationName);
                $("#AreaName").val(parent.AreaName);
            }
            generateVendorCode()


            // 表单提交事件
            form.on('submit(demo2)', function (data) {
                var field = data.field; // 获取表单字段值
                console.log(field);
                var UpdateDto = {
                    //获取表单
                    ItemCode: field.ItemCode,
                    ItemName: field.ItemName,
                    Quantity: field.Quantity,
                    UnitOfMeasure: field.UnitOfMeasure,
                    BatchCode: field.BatchCode,
                    WarehouseName: field.WarehouseName,
                    LocationName: field.LocationName,
                    AreaName: field.AreaName,

                    //数据库值
                    Id : parent.Id ,
                    BatchId : parent.BatchId ,
                    ProducedTime : parent.ProducedTime ,
                    ClientId : parent.ClientId ,
                    ClientCode : parent.ClientCode ,
                    ClientName : parent.ClientName ,
                    ClientNick : parent.ClientNick ,
                    WarehouseId : parent.WarehouseId ,
                    WarehouseCode : parent.WarehouseCode ,
                    LocationId : parent.LocationId ,
                    LocationCode : parent.LocationCode ,
                    AreaId : parent.AreaId ,
                    AreaCode : parent.AreaCode ,
                    QuantityReserved : parent.QuantityReserved ,
                    Remark : parent.Remark ,
                    CreateBy : parent.CreateBy ,
                    CreateTime : parent.CreateTime ,
                }
                $.ajax({
                    url: "/Meng/UpdateStock",
                    type: "get",
                    async: true,
                    data: UpdateDto,
                    contentType: "application/json",
                    success: res => {
                        if (res == 1) {
                            alert("修改成功")
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }
                        else {
                            console.log(res.code)
                            alert("修改失败")
                        }
                    }
                });
                console.log("1")
                return false; // 阻止默认 form 跳转
            });
        });

    </script>

</body>
</html>